const MyPlugin = {}

MyPlugin.install = (Vue, options) => {
  Vue.prototype.$globalData = {
    name: 'yanhua',
    age: options.age
  }
  // 没有结合实例的这个使用场景
  // 但是函数定义是可以有的
  // Vue.prototype.$changeGlobalData = function(data) {
  //   this.$globalData.name = data
  // }

  Vue.component('global-component', {
    template: `
      <h2>global component</h2>
    `
  })

  Vue.mixin({
    methods: {
      showMsg(msg) {
        console.log(msg)
      }
    },

    mounted() {
      if (this.$options.abc) {
        this.$options.abc()
      }
    },
  })

  Vue.directive('myon', (el, binding) => {
    const { arg, value } = binding
    document.addEventListener(arg, value, false)
  })
}

export {
  MyPlugin
}